package com.lxyk.yygh.sms.receiver;

import com.lxyk.yygh.common.rabbit.constant.MqConst;
import com.lxyk.yygh.sms.service.SmsService;
import com.lxyk.yygh.vo.msm.MsmVo;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName SmsReceiver
 * @Description TODO
 * @Author FJQ
 * @Date 2023/6/10 20:14
 * @Version 1.0
 **/

@Component
public class SmsReceiver {
    @Autowired
    private SmsService smsService;

    //监听队列里面是否有内容，有就进行方法调用，短信的发送，订阅到这个内容，往队列中放入发送的请求  最终完成发送
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = MqConst.QUEUE_MSM_ITEM, durable = "true"),
            exchange = @Exchange(value = MqConst.EXCHANGE_DIRECT_MSM),
            key = {MqConst.ROUTING_MSM_ITEM}
    ))

    public void send(MsmVo msmVo, Message message, Channel channel) {
        smsService.send(msmVo);
    }

}
